﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Egora.Pvp.Test
{
  [TestFixture]
  public class PvpTokenTest
  {
    [Test]
    public void ChainedTokenTest()
    {
      NameValueCollection headers = new NameValueCollection()
                                      {
                                        {"X-Version","1.9"},
                                        {"X-AUTHENTICATE-participantId","AT:L6:1234789"},
                                        {"X-AUTHENTICATE-UserId","mmustermann@kommunalnet.at"},
                                        {"X-AUTHENTICATE-cn","Max Mustermann"},
                                        {"X-AUTHENTICATE-gvGid","AT:B:0:LxXnvpcYZesiqVXsZG0bB=="},
                                        {"X-AUTHENTICATE-gvOuId","AT:GGA-60420:0815"},
                                        {"X-AUTHENTICATE-Ou","Meldeamt"},
                                        {"X-AUTHENTICATE-gvOuOKZ","AT:GGA-60420-Abt13"},
                                        {"X-AUTHENTICATE-mail","max.mustermann@hatzendorf.steiermark.at"},
                                        {"X-AUTHENTICATE-tel","+43 3155 5153"},
                                        {"X-AUTHENTICATE-gvSecClass","2"},
                                        {"X-AUTHORIZE-roles","Beispielrolle(GKZ=60420)"},
                                      };
      PvpToken token=new PvpToken(headers);
      string result = token.GetChainedSoapFragment().OuterXml;
      Assert.IsTrue(
        result.Contains(
          @"<pvpChainedToken version=""1.9"" xmlns=""http://egov.gv.at/pvp1.xsd"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">"))
      ;
      Assert.IsTrue(result.Contains("<participantId>AT:L6:1234789</participantId>"));
      Assert.IsTrue(result.Contains("<userId>mmustermann@kommunalnet.at</userId>"));
      Assert.IsTrue(result.Contains("<cn>Max Mustermann</cn>"));
      Assert.IsTrue(result.Contains("<ou>Meldeamt</ou>"));
      Assert.IsTrue(result.Contains("<gvOuOKZ>AT:GGA-60420-Abt13</gvOuOKZ>"));
      Assert.IsTrue(result.Contains("<gvSecClass>2</gvSecClass>"));
      Assert.IsTrue(result.Contains("<gvGid>AT:B:0:LxXnvpcYZesiqVXsZG0bB==</gvGid>"));
      Assert.IsTrue(result.Contains("<gvOuId>AT:GGA-60420:0815</gvOuId>"));
      Assert.IsTrue(result.Contains("<mail>max.mustermann@hatzendorf.steiermark.at</mail>"));
      Assert.IsTrue(result.Contains("<tel>+43 3155 5153</tel>"));
      Assert.IsTrue(result.Contains("</userPrincipal></authenticate>"));
      Assert.IsTrue(result.Contains(@"<role value=""Beispielrolle""><param><key>GKZ</key><value>60420</value></param></role>"));
    }
  }
}
